feat: skip hash shuffle for date_bin/date_trunc on Range([timestamp]) - #24501
Open
NGA-TRAN wants to merge 12 commits into
Open
feat: skip hash shuffle for date_bin/date_trunc on Range([timestamp])#24501NGA-TRAN wants to merge 12 commits into
NGA-TRAN wants to merge 12 commits into
Conversation
Pin today's Partial + hash RepartitionExec + Final plan for GROUP BY key, date_bin(timestamp) on a table that is already Range([timestamp]) and sorted on (key, timestamp), so a follow-up can remove the shuffle. Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24501 +/- ##
==========================================
+ Coverage 81.32% 81.46% +0.14%
==========================================
Files 1117 1118 +1
Lines 396269 400318 +4049
Branches 396269 400318 +4049
==========================================
+ Hits 322260 326130 +3870
+ Misses 55186 55174 -12
- Partials 18823 19014 +191 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Use generic column and table names so the coverage does not expose a metrics-specific schema. Co-authored-by: Cursor <cursoragent@cursor.com>
Accept RecordBatches and optional file sort order so the time-bin table reuses the same registration path. Co-authored-by: Cursor <cursoragent@cursor.com>
Treat Range([x]) as a subset of KeyPartitioned([..., f(x), ...]) when f is monotonic and bins do not straddle split points, so GROUP BY key, date_bin/date_trunc can stream without a hash RepartitionExec. Co-authored-by: Cursor <cursoragent@cursor.com>
NGA-TRAN
force-pushed
the
feat/issue-23569-range-date-bin-trunc
branch
from
August 20, 2026 15:44
05705f6 to
b26846d
Compare
Drop the local order-preserving walk and scalar predecessor so date_bin/date_trunc range projection uses EquivalenceProperties and interval_arithmetic instead of duplicating them. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
NGA-TRAN
marked this pull request as ready for review
August 20, 2026 19:16
…che#24500 Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
Author
|
Tag @gene-bordegaray and @jayshrivastava for review |
jayshrivastava
approved these changes
Aug 21, 2026
jayshrivastava
left a comment
Contributor
There was a problem hiding this comment.
Looks good. Far better than my approach in #23536.
I left some comments re. completeness.
gene-bordegaray
left a comment
Contributor
There was a problem hiding this comment.
all my comments largely ditto @jayshrivastava I can take a review when these are addressed 👍
…atisfaction Require matching SortOptions so -x is not treated as monotonic, try every monotonic projection candidate, and check date_bin disjointness even when subset satisfaction is disabled. Co-authored-by: Cursor <cursoragent@cursor.com>
NGA-TRAN
commented
Aug 25, 2026
NGA-TRAN
left a comment
Contributor
Author
There was a problem hiding this comment.
@jayshrivastava & @gene-bordegaray
I have addressed all Jayant's comments
Range([x]) grouping by a split-aligned date_bin/date_trunc of x is Exact when that transform is the whole key, and Subset only when extra keys remain and subset satisfaction is allowed. Co-authored-by: Cursor <cursoragent@cursor.com>
Add unit coverage for empty keys, multi-split disjointness, and evaluate/project error paths, plus SLTs for GROUP BY date_bin/date_trunc without extra grouping columns. Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
A table that is range-partitioned on
timestamp(for example by hour) and grouped bydate_bin/date_truncof that timestamp is already partition-disjoint when bins do not straddle split points. DataFusion still planned Partial → hashRepartitionExec→ Final.After this change,
Range([timestamp])subset-satisfiesKeyPartitioned([key, f(timestamp)])whenfis monotonic (date_bin,date_trunc) and evaluatingfat each split vs. its predecessor shows the bins are disjoint. Aggregation then runs as one streamingSinglePartitionedstep withordering_mode=Sorted.Bins that do straddle the split (for example
date_trunc('day')on hour-partitioned data) still hash-repartition.#24500's expected plan changes from:
to:
What changes are included in this PR?
Rangethrough monotonic grouping expressions when bins stay disjoint.SanityCheckPlanacceptsSinglePartitionedoverRange([timestamp]).range_sorted_time_bin_agg.sltfordate_bin(60s)anddate_trunc('hour')(no shuffle) anddate_trunc('day')(shuffle remains).Are these changes tested?
partitioning.rsfor aligneddate_bin/date_trunc('hour')vs unaligned split anddate_trunc('day').cargo test --test sqllogictests -- range_sorted_time_bin_agg.sltAre there any user-facing changes?
Queries that group by
date_bin/date_truncof a range-partitioned timestamp may skip a hash shuffle when bins do not cross file-group boundaries. Results are unchanged.Test plan
cargo test -p datafusion-physical-expr --lib -- partitioningcargo test --test sqllogictests -- range_sorted_time_bin_agg.sltCo-author with Cursor